<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" id="ID" value="">
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required"  placeholder="请输入用户名" value="" class="layui-input">
            <tip>填写角色的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">描述</label>
        <div class="layui-input-block">
            <input type="text" name="description" lay-verify="required" lay-reqtext="描述不能为空" placeholder="请输入描述" value="" class="layui-input">
            <tip>填写角色的描述。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="/layui/layui.js"></script>
<script>
    layui.use(['form','layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //获取当前书的id
        var id=layui.sessionData("editRole")["role-id"];
        $("#ID").val(id);
        $.get("/updateRole/"+id,{},function (msg) {
            if (msg.code=="0"){
                $("[name='id']").val(msg.data.id);
                $("[name='name']").val(msg.data.name);

            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //提交Ajax请求
            $.ajax({
                url: "/updateRole",
                type: "GET",
                dataType: "json",
                data:data.field,
                success:function (result) {
                    if(result.code=="0"){
                        layer.msg(result.msg,{time:2000});
                        setTimeout(function () {
                            /*  方法一：关闭弹出层，刷新父界面*/
                            //获取弹出窗口的id
                            var index=parent.layer.getFrameIndex(window.name);
                            //关闭弹出层
                            parent.layer.close(index);
                            // table.render中的id
                            parent.location.reload();

                        },1000);
                    } else if (result.code=="100000"){
                        layer.msg(result.msg,{time:2000});
                    }else if (result.code=="100003"){
                        layer.msg(result.msg,{time:2000});
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>